//
//  XKRechargeTypeSelectView.m
//  xk100
//
//  Created by xiaokang on 2017/5/27.
//  Copyright © 2017年 xiaokang. All rights reserved.
//

#import "XKRechargeTypeSelectView.h"

@interface XKRechargeTypeSelectView ()

@property (nonatomic, strong) UIImageView   *iconImageView;
@property (nonatomic, strong) UILabel       *titleLabel;
@property (nonatomic, strong) UILabel       *detailLabel;
@property (nonatomic, strong) UIButton      *selectButton;

@end
@implementation XKRechargeTypeSelectView
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initSubviews];
    }
    return self;
}


#pragma mark - 子控件
- (void)initSubviews {
    _iconImageView = [[UIImageView alloc] init];
    [self addSubview:_iconImageView];
    
    _titleLabel = [UILabel getLabWithText:@""
                                 textFont:Font_15
                                textColor:[UIColor darkGrayColor]
                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:_titleLabel];
    
    _detailLabel = [UILabel getLabWithText:@""
                                  textFont:Font_13
                                 textColor:[UIColor lightGrayColor]
                             textAlignment:NSTextAlignmentLeft];
    [self addSubview:_detailLabel];
    
    _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_selectButton setContentMode:UIViewContentModeScaleAspectFit];
    [_selectButton setImage:[UIImage imageNamed:@"unchecked"] forState:UIControlStateNormal];
    [_selectButton setImage:[UIImage imageNamed:@"checked"] forState:UIControlStateSelected];
    [_selectButton addTarget:self action:@selector(selectButtonClickEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_selectButton];
    
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20*Scale_W);
        make.top.mas_equalTo(self).offset(10*Scale_W);
        make.size.mas_equalTo(CGSizeMake(40*Scale_W, 40*Scale_W));
        make.bottom.mas_equalTo(self).offset(-10*Scale_W).priorityHigh();
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_iconImageView.mas_right).offset(8*Scale_W);
        make.top.mas_equalTo(_iconImageView);
    }];
    
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_titleLabel);
        make.bottom.mas_equalTo(_iconImageView);
    }];
    
    [_selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-20*Scale_W);
        make.width.mas_equalTo(16*Scale_W);
        make.height.mas_equalTo(16*Scale_W);
        make.centerY.mas_equalTo(_iconImageView);
    }];
}

- (void)setIconImageName:(NSString *)iconImageName {
    _iconImageName = iconImageName;
    _iconImageView.image = [UIImage imageNamed:iconImageName];
}

- (void)setTitleString:(NSString *)titleString {
    _titleString = titleString;
    _titleLabel.text = titleString;
}

- (void)setDetailString:(NSString *)detailString {
    _detailString = detailString;
    _detailLabel.text = detailString;
}

- (void)setButtonTag:(NSInteger)buttonTag {
    _buttonTag = buttonTag;
    [_selectButton setTag:buttonTag];
}

- (void)selectButtonClickEvent:(UIButton *)sender {
    [_selectButton setSelected:YES];
    if (_SelectedBlock) {
        _SelectedBlock(sender.tag);
    }
}

- (void)setSelected:(BOOL)selected {
    _selected = selected;
    [_selectButton setSelected:selected];
}

@end
